#include <STC15F2K60S2.H>
#include <intrins.H>

sbit Tx=P1^0;
sbit Rx=P1^1;

void Delay13us()		//@12.000MHz
{
	unsigned char i;

	_nop_();
	_nop_();
	i = 36;
	while (--i);
}

void Ultra_Init()
{
	Tx=1;
	Delay13us();
	Tx=0;
	Delay13us();
}

unsigned char Ultra_Wave_Dat()
{
	unsigned int Temp;
	CMOD=0x00;
	CH=CL=0;
	Ultra_Init();
	CR=1;
	while((Rx==1)&&(CF==0));
	CR=0;
	if(CF==0)
	{
		Temp=(CH<<8)|CL;
		return Temp*0.017;
	}
	else
	{
		CF=0;
		return 0;
	}
}